﻿using STHPMS1.DAL.D_Core;
using System.Data;
using ServiceStack.OrmLite;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore.I_DAL.Repository;
using System.Collections.Generic;
using System.Data.SqlClient;

namespace STHPMS1.DAL.D_Repository
{
    public class Dr_Repair_MidRepository : DalBase, IDr_Repair_MidRepository
    {


        /// <summary>
        /// 决策路段的弯沉检测点总和
        /// </summary>
        /// <param name="segid">决策路段</param>
        /// <returns></returns>
        public int Sgeid_RepdeflCount(string segid)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            return conn.Scalar<int>("select count(*) from S_RDPSSI where UNIT in(select UNIT from B_INVNTORY_UNIT where SEGID='" + segid + "')");
        }

        /// <summary>
        /// 决策路段的平均弯沉值
        /// </summary>
        /// <param name="sgeid">决策路段</param>
        /// <returns></returns>
        public double Sgeid_AvageRepdefl(string segid)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            return conn.Scalar<int>("select SUM(REPDEFL)/COUNT(REPDEFL) from S_RDPSSI where UNIT in(select UNIT from B_INVNTORY_UNIT where SEGID='" + segid + "')");
        }

        /// <summary>
        /// 决策路段弯沉标准差  公式上部分
        /// </summary>
        /// <param name="segid">决策路段</param>
        /// <param name="avagerepdefl">决策路段的平均弯沉值</param>
        /// <returns></returns>
        public double Segid_RepdeflCha(string segid, double avagerepdefl)
        {
            IDbConnection conn = Adapter.OpenDbConnection();
            return conn.Scalar<int>("select sum(power(REPDEFL-" + avagerepdefl + ",2)) from S_RDPSSI where UNIT in(select UNIT from B_INVNTORY_UNIT where SEGID='" + segid + "')");
        }

    }
}
